#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define LL long long
#define ULL unsigned long long

constexpr LL inf = 0x3f3f3f3f3f3f3f3f;
const int N = 2005;
int n; LL a[N];
LL f[N][N];

inline void init()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
}

inline void solve()
{
    memset(f, -0x3f, sizeof(f));
    f[1][0] = 0;
    for (int i = 1; i < n; i++)
    {
        for (int j = 0; j < i; j++)
        {
            if (f[i][j] != -inf)
            {
                f[i+1][j] = max(f[i+1][j], f[i][j] + ((a[i+1] == a[i]) ? a[i] : 0));
                f[i+1][i] = max(f[i+1][i], f[i][j] + ((a[i+1] == a[j]) ? a[j] : 0));
            }
        }
    }

    LL ans = -inf;
    for (int i = 0; i < n; i++)
        ans = max({ans, f[n][i]});
    printf("%lld\n", ans);
}

int main()
{
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int T; scanf("%d", &T);
    while (T--)
    {
        init();
        solve();
    }

    return 0;
}